<template>
  <div class="box b1">
    <img src="../../images/g.png" alt="" />
  </div>
  <button @click="add">添加</button>
</template>
<script>
import html2canvas from 'html2canvas'
import gsap from '../../libs/gsap-3.11.1.min.js'
export default {
  data() {
    return {
      style: {},
      url: '',
      data: {
        a: 1,
        b: 2,
        childs: [
          {
            a: 2,
            b: 3,
            childs: []
          },
          {
            a: 4,
            b: 5,
            childs: [
              {
                a: 2,
                b: 999,
                childs: [
                  {
                    a: 2,
                    b: 333,
                    childs: []
                  },
                  {
                    a: 2,
                    b: 2
                  },
                  {
                    a: 3,
                    b: 4
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  },
  methods: {
    add() {
      let list = this.scan(this.data)
      console.log(list)
    },
    add2() {},
    scan(obj, level = 0) {
      let obj_a_2 = []
      if (obj.a === 2) {
        obj_a_2.push({
          level,
          a: obj.a,
          b: obj.b
        })
      }
      if (obj.childs) {
        obj.childs.forEach((res, index) => {
          obj_a_2 = obj_a_2.concat(this.scan(res, level + '-' + index))
        })
      }
      return obj_a_2
    }
  },
  mounted() {}
}
</script>
<style type="text/css" lang="scss">
.box {
  border: 1px solid #000;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: 100px;
  height: 100px;
  //transform: scale(10);
  img {
    display: block;
    width: 100px;
    height: 100px;
  }
}
</style>
